
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define SOFTWARE_NAME 	"udp"

static void print_hex(const uint8_t *buffer, size_t size)
{
  int i;

  for(i = 0; i < size; i++) {
    printf("%02x ", (unsigned char)buffer[i]);
  }
  printf("\n");
}
int main(int argc, char **argv)
{
  int fd, rc = 0, port;
  ssize_t nread;
  struct sockaddr_in addr;
  uint8_t buf[1024];

  port = atoi(argv[1]);
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd < 0) {
    printf("服务端Socket创建失败");
      return -1;
  }
  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(port);
  bind(fd, (struct sockaddr *) &addr, sizeof(addr));
  printf("udp server:%d open fd:%d\n", port, fd);

  while (1) {
    nread = recv(fd, buf, sizeof(buf), 0);
    if (nread > 0) {
      print_hex(buf, nread);
    }
  }

	return rc;
}
/*
  nread = recvfrom(fd, recv_buf, sizeof(recv_buf), 0,
      (struct sockaddr *)&client_addr, &peer_addrlen);
      */
